package com.web;

import com.config.FeignConfig;
import com.service.RemoteService;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Callable;

@Slf4j
@RestController
public class HelloController {
    @Autowired
    RemoteService remoteService;

    @Autowired
    FeignConfig.FeignClient feignClient;

    @RequestMapping("/feign/remote/invoke")
    public String remoteInvokeUseFeign(){
        return feignClient.remoteSayHello();
    }

    @RequestMapping("/remote/invoke")
    public String remoteInvoke(){
        return remoteService.sayHello();
    }


    @RequestMapping("/hello")
    public String hello(){
        MDC.put("first","h");
        MDC.put("last","cj");
        log.info("Hello world!");
        return "hello world";
    }
    @RequestMapping("async")
    public Callable<String> async(){
        return new Callable<String>() {
            @Override
            public String call() throws Exception {
                Thread.sleep(1000);
                log.info("this is async request");
                return "this is async request";
            }
        };
    }
}
